﻿//申购页面函数
var pagesize = "15";
var pageindex = "1";
var lilenth = 0;var lilenth2 = 0;
var leftpos = 0;var leftpos2 = 0;
var leftcount = 0;var leftcount2 = 0;
$(function () {

    //选项卡切换
    $('#div_detail').Tabs({
        menuObj: $(".invest_l_b_menu"),
        tabObj: $(".invest_l_b_box"),
        hideClass: 'invest_l_b_hide',
        event: 'click'
    });

    //加载分页    initSubscribesPagin($("#divPagination").attr("totalcount"));    lilenth = $(".list-h li").length;        lilenth2 = $(".list-g-h li").length;        $(".list-h").css("width", lilenth * 200);    $(".list-g-h").css("width", lilenth2 * 200);        $("#imgLeft").attr("src", "http://image.tuandai.com/img/left_g.gif");    $("#spec-left").css("cursor", "default");    $("#spec-g-left").css("cursor", "default");        var width = $("#preview").width();    $("#spec-list").css("width", 800).css("margin-left", 2).css("margin-right", 2);    $("#spec-g-list").css("width", 600).css("margin-left", 2).css("margin-right", 2);        //相关资料图片    if (lilenth > 4) {        //图片右侧        $("#spec-right").click(function () {            if (leftcount >= 0) {                $("#imgLeft").attr("src", "http://image.tuandai.com/img/scroll_left.gif");                $("#spec-left").css("cursor", "pointer");            }            if (lilenth - leftcount < 5) {                $("#imgRight").attr("src", "http://image.tuandai.com/img/right_g.gif");                $("#spec-right").css("cursor", "default");            }            else {                leftpos = leftpos - 150;                leftcount = leftcount + 1;                $(".list-h").animate({ left: leftpos }, "slow");                if (lilenth - leftcount < 5) {                    $("#imgRight").attr("src", "http://image.tuandai.com/img/right_g.gif");                    $("#spec-right").css("cursor", "default");                }            }        });        //图片左侧        $("#spec-left").click(function () {            if (lilenth - leftcount > 4) {                $("#imgRight").attr("src", "http://image.tuandai.com/img/scroll_right.gif");                $("#spec-right").css("cursor", "pointer");            }            if (leftcount < 1) {                $("#imgLeft").attr("src", "http://image.tuandai.com/img/left_g.gif");                $("#spec-left").css("cursor", "default");            }            else {                leftpos = leftpos + 150;                leftcount = leftcount - 1;                $(".list-h").animate({ left: leftpos }, "slow");                if (leftcount < 1) {                    $("#imgLeft").attr("src", "http://image.tuandai.com/img/left_g.gif");                    $("#spec-left").css("cursor", "default");                }            }        })    }    else {        $("#imgRight").attr("src", "http://image.tuandai.com/img/right_g.gif");        $("#spec-right").css("cursor", "default");    }        if (lilenth2 > 4) {        //图片右侧        $("#spec-g-right").click(function () {            if (leftcount2 >= 0) {                $("#spec-g-left").css("cursor", "pointer");            }            if (lilenth2 - leftcount2 < 5) {                $("#spec-g-right").css("cursor", "default");            }            else {            	leftpos2 = leftpos2 - 150;            	leftcount2 = leftcount2 + 1;                $(".list-g-h").animate({ left: leftpos2 }, "slow");                if (lilenth2 - leftcount2 < 5) {                    $("#spec-g-right").css("cursor", "default");                }            }        });        //图片左侧        $("#spec-g-left").click(function () {            if (lilenth2 - leftcount2 > 4) {                $("#spec-g-right").css("cursor", "pointer");            }            if (leftcount2 < 1) {                $("#spec-g-left").css("cursor", "default");            }            else {            	leftpos2 = leftpos2 + 150;                leftcount2 = leftcount2 - 1;                $(".list-g-h").animate({ left: leftpos2 }, "slow");                if (leftcount < 1) {                    $("#spec-g-left").css("cursor", "default");                }            }        })    }    else {        $("#spec-g-right").css("cursor", "default");    }        $("#spec-list img").bind("mouseover", function () {        $(this).css({            "border": "2px solid #ff6600",            "padding": "1px"        });    }).bind("mouseout", function () {        $(this).css({            "border": "1px solid #ccc",            "padding": "2px"        });    });        $("#spec-g-list img").bind("mouseover", function () {        $(this).css({            "border": "2px solid #ff6600",            "padding": "1px"        });    }).bind("mouseout", function () {        $(this).css({            "border": "1px solid #ccc",            "padding": "2px"        });    })})
//加载申购列表
function SubscribeList() {
    $("#Subscribelist").nextAll().remove();
    $("<tr><td colspan=\"6\" align=\"center\">数据加载中...</td></tr>").insertAfter('#Subscribelist');
    jQuery.ajax({
        async: false,
        type: "post",
        url: "/ajaxCross/ajax_invest.ashx",
        dataType: "json",
        data: { Cmd: "GetSubscribePageList", projectid: $("#btnSubscribe").attr("attrid"), pagesize: pagesize, pageindex: pageindex },
        success: function (jsonstr) {
            $("#Subscribelist").nextAll().remove();
            var html = new Array();
            var str = "";
            if (jsonstr.result == "1") {
                var temp1 = pagesize * (pageindex - 1);
                var autoDesc = "";
                for (var i = 0; i < jsonstr.list.length; i++) {
                    autoDesc = jsonstr.list[i].IsAuto == "True" ? "1" : "0";
                    str = "<tr>" +
                          "<td>" + parseInt(parseInt(temp1) + parseInt(i + 1)) + "</td>" +
                          "<td>" + jsonstr.list[i].NickName + "</td>" +
                          "<td>" + jsonstr.list[i].InterestRate + "%</td>" +
                          "<td><div style=\"padding-right:55px;color:#f60;text-align:right;\">￥" + jsonstr.list[i].Amount + "</div></td>" +
                          "<td><img style=\"width:48px; height:19px;\" alt=\"\" src=\"http://image.tuandai.com/img/auto_" + autoDesc + ".png\" /></td>" +
                          "<td>" + jsonstr.list[i].AddDate + "</td>" +
                        "</tr>"
                    html.push(str);
                }
                $(html.join("")).insertAfter('#Subscribelist');
                if (parseInt(jsonstr.totalcount) != parseInt($("#divPagination").attr("totalcount"))) {
                    initSubscribesPagin(jsonstr.totalcount);
                }
            }
            else {
                $("<tr><td colspan=\"6\" align=\"center\">暂没有人投标...</td></tr>").insertAfter('#Subscribelist');
            }
        }
    });

}


//分页申购列表
function initSubscribesPagin(recordCount) {
    var num_entries = recordCount;
    $("#divPagination").pagination(num_entries, {
        callback: getSubscribes,
        items_per_page: pagesize,
        num_display_entries: 5,
        current_page: parseInt(pageindex-1),
        num_edge_entries: 2,
        link_to: "#Subscribelist",
        prev_text: "上一页",
        next_text: "下一页",
        ellipse_text: "...",
        prev_show_always: true,
        next_show_always: true,
        renderer: "defaultRenderer",
        show_if_single_page: false,
        load_first_page: true
    });
}


//获取投资人列表
function getSubscribes(page_index, jq) {
    if (parseInt(pageindex - 1) == page_index) {
        return false;
    }
    pageindex = (page_index + 1);
    SubscribeList();
    return false;
}


//打开图片查看层
function openImage(projectId, id) {
    var url = "/View/invest_images.aspx?projectId=" + projectId + "&id=" + id;
    PopLayer.iframe(url);
}

